/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ucjava.chat.commserve.tonys.client;
import uc.edu.server.*; // for Message and IChatService interface
/**
 *
 * @author tony
 */
public class ChatServiceStub implements IChatService
{
    private MessageStore messageStore = new MessageStore();
    

    /**
     * The client calls this to send a single message
     * to the server. The client does not know the ID,
     * so it sends a simple Message object instead of
     * a MessageWithID. 
     * @param parameter
     * @return String - "OK" if successful, "FAIL" on error.
     */
    @Override
    public String sendMessage(Message parameter)
    {
        MessageWithID msg = new MessageWithID(parameter);
        return (messageStore.addMessage(msg) == 0L) ? "FAIL" : "OK";
    }

    /**
     * Stub method to generate a dummy message.
     * @return Message object
     * Null if there are no messages, or none > lastID
     */
    @Override
    public MessageWithID receiveMessage(long lastID)
    {
        return messageStore.nextMessage(lastID);
    }
    
}
